package cn.tedu.m3;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class Consumer {
    //每个 @RabbitListener 注解，都会启动一个新的消费者的。
    @RabbitListener(bindings = @QueueBinding( //绑定队列与交换机的关系
            value = @Queue,//随机命名，非持久，独占，自动删除（默认）
            exchange = @Exchange(name = "logs",declare = "false"))) //declare="false"表示不创建交换机，只是引用它。
    public void receive1(String msg){
        System.out.println("消费者1收到："+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            exchange = @Exchange(name = "logs",declare = "false")))
    public void receive2(String msg){
        System.out.println("消费者2收到："+msg);
    }

}
